package com.niuke;

import java.util.HashSet;
import java.util.Scanner;

/**
 * @ClassName : HJ41
 * @Author : kele
 * @Date: 2023/4/2 16:56
 * @Description :
 */
public class HJ41 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            HashSet<Integer> set = new HashSet<>();//存放所有可能的结果，不用担心重复问题
            set.add(0);//初始化为0
            int n = in.nextInt();//个数
            int[] w = new int[n];
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                w[i] = in.nextInt();//砝码的重量
            }
            for (int i = 0; i < n; i++) {
                nums[i] = in.nextInt();//砝码个数
            }

            for (int i = 0; i < n; i++) {

                HashSet<Integer> w_set = new HashSet<>();

                for (int j = 0; j <= nums[i]; j++) {

                    int weigth = w[i] * j;

                    for (Integer integer : set) {
                        w_set.add(weigth + integer);
                    }
                }
                set.addAll(w_set);
            }

            System.out.println(set.size());

        }
    }
}
